package _mst;

import java.util.Arrays;

/**
 * 面试题 01.02. 判定是否互为字符重排
 */
public class T0102 {
    public boolean CheckPermutation1(String s1, String s2) {
        char[] charArray1 = s1.toCharArray();
        Arrays.sort(charArray1);
        char[] charArray2 = s2.toCharArray();
        Arrays.sort(charArray2);
        return new String(charArray1).equals(new String(charArray2));
    }

    public boolean CheckPermutation2(String s1, String s2) {
        int[] ints = new int[26];
        for (char c : s1.toCharArray()) ints[c - 'a']++;
        for (char c : s2.toCharArray()) ints[c - 'a']--;
        for (int anInt : ints) if (anInt != 0) return false;
        return true;
    }
}
